#pragma once

#include<string.h>
#include<assert.h>
#include<iostream>

using namespace std;

namespace yyh
{
	class string
	{
	public:
		typedef char* iterator;

		string(const char* str = " ");

		string(const string& s);

		string& operator =(const string& s);

		~string();

		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size;
		}

		void push_back(char ch);

		void append(const char* str);

		string& operator +=(char ch);

		string& operator +=(const char* str);

		void swap(string& s);

		void clear()
		{
			_str[0] = '\0';
			_size = 0;
		}

		const char* c_str() const
		{
			return _str;
		}

		size_t size() const
		{
			return _size;
		}

		size_t capacity() const
		{
			return _size;
		}

		bool empty() const
		{
			return _size == 0;
		}

		void reserve(size_t n);

		void resize(size_t n, char ch = '\0');

		char& operator [](size_t pos);

		const char& operator [](size_t pos) const;

		bool operator ==(const string& s) const;

		bool operator !=(const string& s) const;

		bool operator <(const string& s) const;

		bool operator <=(const string& s) const;

		bool operator >(const string& s) const;

		bool operator >=(const string& s) const;

		size_t find(char c, size_t pos = 0);

		size_t find(const char* str, size_t pos = 0);

		void insert(size_t pos, size_t n, char ch);

		void insert(size_t pos, const char* str);

		void erase(size_t pos = 0, size_t len = npos);

	private:
		char* _str;
		size_t _size;
		size_t _capacity;
		const static size_t npos;
	};

	void test1();
	void test2();
	void test3();
}